package com.happle.gcmclient.backendmanager.task;

import android.content.Context;
import android.os.AsyncTask;

import com.happle.gcmclient.backendmanager.BackendManager;
import com.happle.gcmclient.config.Constants;
import com.happle.gcmclient.managers.MessagesManager;
import com.happle.gcmclient.obj.ConversationObj;
import com.happle.gcmclient.obj.ConversationsNotSyncObj;

/**
 * Created by Inna on 19.04.14.
 */
public class DeleteConversationTask extends AsyncTask<Void, Void, Integer> {
    private ConversationObj convObj = new ConversationObj();
    private String _registration_id = "";
    private int _statusDeleted = -1;
    private Context mContext;

    public DeleteConversationTask (ConversationObj conversationObj, String registration_id, Context context) {
        convObj = conversationObj;
        _registration_id = registration_id;
        mContext = context;
    }
    @Override
    protected Integer doInBackground(Void... params) {
        int result  = Constants.FAILED;
        try {
            BackendManager bManager = new BackendManager();
            result = bManager.deleteConversation(convObj, _registration_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (result == Constants.FAILED) {
            MessagesManager MsgManager = new MessagesManager(mContext);
            MsgManager.saveNotSynchronizedConversation(new ConversationsNotSyncObj(convObj.get_wave_id(), convObj.get_lng_id(), convObj.is_is_owner(), _statusDeleted));
        }
        return result;
    }
}
